package helper;

import java.util.HashMap;
import java.util.LinkedHashMap;

import android.graphics.Color;

public class Settings {
	private static Settings instance = null;

	private static LinkedHashMap<String, LinkedHashMap<String, Integer>> exercises = new LinkedHashMap<String, LinkedHashMap<String, Integer>>();

	public static Exercise lastExerciseDone = new Exercise(11, "Biceps Curls",
			"Weigth");

	private int personID;

	public static LinkedHashMap<String, LinkedHashMap<String, Integer>> getExercises() {
		return exercises;
	}

	public HashMap<String, Integer> exerciseColorMapping = new HashMap<String, Integer>();
	public HashMap<ExercisesEnum, Integer> exerciseNameIDMapping = new HashMap<ExercisesEnum, Integer>();
	public HashMap<String, ExercisesEnum> exNameTypeMapping = new HashMap<String, ExercisesEnum>();
	public static ExercisesEnum lastExercise;

	public static int DISPLAY_WIDTH;

	public static int DISPLAY_HEIGHT;
	public HashMap<Integer, String> monthMapping = new HashMap<Integer, String>();

	private Settings() {

		/* mapping between Enum and Strings used in GUI */
		exerciseNameIDMapping.put(ExercisesEnum.BICEP_CURLS, 11);
		exerciseNameIDMapping.put(ExercisesEnum.SQUATS, 4);
		exerciseNameIDMapping.put(ExercisesEnum.PUSH_UPS, 2);
		exerciseNameIDMapping.put(ExercisesEnum.PULL_UPS, 1);
		exerciseNameIDMapping.put(ExercisesEnum.SIT_UPS, 3);

		exNameTypeMapping.put(ExercisesEnum.BICEP_CURLS.toString(),
				ExercisesEnum.BICEP_CURLS);
		exNameTypeMapping.put(ExercisesEnum.SQUATS.toString(),
				ExercisesEnum.SQUATS);
		exNameTypeMapping.put(ExercisesEnum.PUSH_UPS.toString(),
				ExercisesEnum.PUSH_UPS);
		exNameTypeMapping.put(ExercisesEnum.PULL_UPS.toString(),
				ExercisesEnum.PULL_UPS);
		exNameTypeMapping.put(ExercisesEnum.SIT_UPS.toString(),
				ExercisesEnum.SIT_UPS);

		/*
		 * mapping between month names and month nr
		 */
		monthMapping.put(1, "Jan");
		monthMapping.put(2, "Feb");
		monthMapping.put(3, "Mar");
		monthMapping.put(4, "Apr");
		monthMapping.put(5, "May");
		monthMapping.put(6, "June");
		monthMapping.put(7, "July");
		monthMapping.put(8, "Aug");
		monthMapping.put(9, "Sept");
		monthMapping.put(10, "Oct");
		monthMapping.put(11, "Nov");
		monthMapping.put(12, "Dec");

		/*
		 * mapping between exercises and colors
		 */
		exerciseColorMapping.put(ExercisesEnum.BICEP_CURLS.toString(),
				Color.argb(255, 255, 230,0));
		exerciseColorMapping.put(ExercisesEnum.SIT_UPS.toString(),
				Color.argb(255, 100, 149, 237));
		exerciseColorMapping.put(ExercisesEnum.SQUATS.toString(),
				Color.argb(255,102,255,102));

		LinkedHashMap<String, Integer> bodyweight = new LinkedHashMap<String, Integer>();
		bodyweight.put("Pulls ups", 1);
		bodyweight.put("Push ups", 2);
		bodyweight.put("Sit ups", 3);
		bodyweight.put("Squat", 4);

		LinkedHashMap<String, Integer> weigth = new LinkedHashMap<String, Integer>();
		weigth.put("Biceps Curls", 11);
		weigth.put("Biceps Flips", 12);
		weigth.put("Biceps Flops", 13);
		weigth.put("Biceps Flps", 14);

		LinkedHashMap<String, Integer> endurance = new LinkedHashMap<String, Integer>();
		endurance.put("Schnell rennen", 21);
		endurance.put("Lang rennen", 22);
		endurance.put("Fest rennen", 23);
		endurance.put("Alm rennen", 24);

		exercises.put("Body Weigth", bodyweight);
		exercises.put("Weigth", weigth);
		exercises.put("Endurance", endurance);		

	}

	public static Settings getInstance() {
		if (instance == null) {
			instance = new Settings();
		}
		return instance;
	}

	public int getExerciseID(String exerciseName) {
		try {

			ExercisesEnum e = exNameTypeMapping.get(exerciseName);
			return exerciseNameIDMapping.get(e);

		} catch (Exception e) {

		}
		return 0;
	}

	/***
	 * 
	 * @param exerciseName
	 * @return returns an array: [0] = Exercise_Group_ID, [1] = Exercise_ID
	 */
	public static Exercise getExerciseId(String exerciseName) {

		for (String s : exercises.keySet()) {
			LinkedHashMap<String, Integer> innerHashMap = exercises.get(s);
			for (String s_in : innerHashMap.keySet()) {
				if (s_in.equals(exerciseName)) {
					Exercise temp = new Exercise(innerHashMap.get(s_in),
							exerciseName, s);
					return temp;
				}
			}
		}
		return new Exercise(-1, "null", "null");
	}

	public int getPersonID() {
		return personID;
	}

	public void setPersonID(int i) {
		personID = i;
	}

	public int getExerciseColor(String selectedExercise) {
		try {
			int c = this.exerciseColorMapping.get(selectedExercise);
			return c;
		} catch (Exception e) {
			return Color.argb(255,255,255,255);
		}

	}

}
